#!/bin/python

import sys,os,math,time;

def distance(X, Y):
    ss = lambda x,y: (x-y)*(x-y);
    vec = list(ss(X[i], Y[i]) for i in range(0,len(X)));
    return math.sqrt(sum(vec));

#def delta_x1(x1, x2):
#    return -2.0*(1-x1) + 200.0 * (x2-x1*x1)*(-2)*x1;

#def delta_x2(x1, x2):
#    return 200.0*(x2-x1*x1);

def delta_x1(x1, x2):
    return 2*x1 - 4;    
def delta_x2(x1, x2):
    return 2*x2 + 4;

if __name__ == "__main__":
    cur = [84.0, -32.0];
    last = list(cur);
    theta = 1e-20;
    minus = lambda x,y: x-y;
    iter = 0;
    step = 0.0005;
    while True:
        a1 = delta_x1(cur[0], cur[1]);
        b1 = delta_x2(cur[0],cur[1]);
        c1 = 1 if max(a1,b1)<1 else max(a1,b1);
        gradient = [a1/c1, b1/c1];
        #gradient = [a1, b1];
        cur = list(last[i] - step*gradient[i] for i in range(0, len(cur)));
        agg = distance(last, cur);
        iter += 1;
        if iter%10000==0:
            print "iter:", iter, "last:",last, "gradient:", gradient, "cur:", cur, "agg:", agg;
        if agg < theta:
            break;
        last = cur;
    print iter, cur;
    
